﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Microsoft.Win32;
using System.Windows;
using System.Xml;
using System.Windows.Controls;

namespace SHomeWorkshop.LunarMind.Commands
{
    /// <summary>
    /// 以此类为模板，制作自定义命令类
    ///     共需要修改１０处！！！
    /// ==============================
    /// 
    /// 设置标题中文本相对于图片的停靠位置的命令。
    /// ★①，修改类名。
    /// </summary>
    public static class SetTextDockBottomCommand
    {
        private static RoutedUICommand routedUICmd;//创建私有字段

        public static RoutedUICommand RoutedUICmd//创建只读静态属性
        {
            get { return routedUICmd; }
        }

        /// <summary>
        /// ★②，修改静态构造方法名。
        /// </summary>
        static SetTextDockBottomCommand()//类型构造器
        {
            //★③，修改两个字符串参数名。★④以及第三个参数的类型名。
            routedUICmd = new RoutedUICommand("SetTextDockBottomCommand", "SetTextDockBottomCommand",
                typeof(SetTextDockBottomCommand),//创建RoutedUICommand对象
                new InputGestureCollection() 
                { 
                    //★⑤，修改此处两个参数，以便挂接快捷键。
                    new KeyGesture(Key.Down,ModifierKeys.Shift,"Shift+↓"),
                });

            cmdBinding.Command = routedUICmd;
            cmdBinding.CanExecute += new CanExecuteRoutedEventHandler(cmdBinding_CanExecute);
            cmdBinding.Executed += new ExecutedRoutedEventHandler(cmdBinding_Executed);
        }

        private static CommandBinding cmdBinding = new CommandBinding();

        public static CommandBinding CmdBinding
        {
            get { return cmdBinding; }
        }

        static void cmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //★⑦，修改此方法的实现。

            KeyStates state = Keyboard.GetKeyStates(Key.Left);

            SetTextDockBottom();
        }

        /// <summary>
        /// 此方法是调用DeleteCommand的Delete来实现。
        /// </summary>
        internal static void SetTextDockBottom()
        {
            if (Globals.SelectedTitlesList != null && Globals.SelectedTitlesList.Count > 0)
            {
                ModifingItem mi = new ModifingItem()
                {
                    IsNeedRefreshTitleAndLinesLocation = true,
                    ModifingName = "设置标题文本相对于图像的停靠位置为：下"
                };

                foreach (Title t in Globals.SelectedTitlesList)
                {
                    if (t.TextDock != Dock.Bottom)
                    {
                        Action actTextDock = new Action(t.ID, -1, t.GetType().Name, "TextDock",
                            t.TextDock.ToString(), Dock.Bottom.ToString());
                        t.TextDock = Dock.Bottom;
                        mi.Add(actTextDock);
                    }
                }

                if (mi.ModifiedPropertyAndValues.Count > 0)
                {
                    Globals.MainWindow.Do(mi);
                    Globals.MainWindow.IsModified = true;
                    Globals.MainWindow.RefreshTitleAndLinesLocation();
                }
            }
        }

        static void cmdBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            //★⑧，修改此方法的实现。
            if (Globals.SelectedTitlesList != null && Globals.SelectedTitlesList.Count > 0)
            {
                e.CanExecute = true;
            }
            else e.CanExecute = false;
        }
    }
}
